Skip to content

fix(workflow): retry server-sent CANCELLED during orchestration waits (closes #1246) - #1370

Open
NaniToka wants to merge 5 commits into
dapr:mainfrom
NaniToka:fix/workflow-retry-server-cancelled-wait-1246
Open

NaniToka wants to merge 5 commits into
dapr:mainfrom
NaniToka:fix/workflow-retry-server-cancelled-wait-1246

Conversation

@NaniToka

@NaniToka NaniToka commented Nov 14, 2026 •

Copy link
Copy Markdown

Description

Implements the proposal in #1246 by @CasperGN: re-issue WaitForInstanceCompletion and WaitForInstanceStart (sync and async) when the server ends the wait call with grpc.StatusCode.CANCELLED and the caller's timeout has not expired.

Problem

When daprd shuts down or restarts mid-wait (e.g. rollouts, pod restarts, runtime reload), the actors router cancels all in-flight calls it tracks (dapr/dapr#10566). Previously, this caused wait_for_orchestration_completion and wait_for_orchestration_start to abort and raise grpc.RpcError(StatusCode.CANCELLED) immediately, even though the workflow is intact and running on durable storage.

Solution

  1. Add CANCELLED to _TRANSIENT_RPC_CODES:
    • Added grpc.StatusCode.CANCELLED to _TRANSIENT_RPC_CODES in both TaskHubGrpcClient (dapr/ext/workflow/_durabletask/client.py) and AsyncTaskHubGrpcClient (dapr/ext/workflow/_durabletask/aio/client.py).
    • Callers' timeout deadlines remain strictly enforced: _is_deadline_cancellation() maps deadline expiration to _TransientTimeout (TimeoutError), ensuring that caller-specified deadlines are never exceeded.
  2. Refresh Transient Grace Window on In-Flight Wait Cancellations (Capped):
    • In unbounded wait mode (timeout=0), when a healthy wait was in-flight and held by daprd before being cancelled by a restart, transient_deadline and backoff are refreshed, capped at _MAX_CONSECUTIVE_TRANSIENT_RESETS = 3 to prevent infinite loops from persistent proxy idle timeouts or sidecar crash loops.
    • Immediate/consecutive errors (e.g. from an unavailable sidecar or proxy reset) continue to count down the 30s grace window before propagating the original error.
    • If the client is closed locally while a wait is in-flight, CANCELLED is re-raised immediately without retrying or invoking calls on the closed channel.
  3. Public API Additions (for Release Notes):
    • Added is_closed property to both sync and async DaprWorkflowClient (and underlying TaskHubGrpcClient / AsyncTaskHubGrpcClient) to inspect channel closure status.
    • Added close(), aclose(), and async context manager (async with) support to dapr.ext.workflow.aio.DaprWorkflowClient.
    • Added context manager (with) support to dapr.ext.workflow.DaprWorkflowClient.
  4. Tests:
    • Flipped the tests from Add stateful-history delta delivery to the workflow worker #1112 (test_cancelled_within_deadline_still_propagates, test_cancelled_unbounded_wait_still_propagates in sync and async) to verify that CANCELLED is absorbed, retried with backoff, and succeeds when the subsequent wait call returns the workflow state.
    • Added tests verifying that multiple restarts separated by long waits succeed without exhausting the transient window.
    • Added tests verifying that persistent cancellations give up with grpc.RpcError once the grace window or consecutive reset cap elapses.
    • Added tests verifying client closure marks is_closed and avoids re-invoking on closed channels.
    • Added tests for is_closed, close(), aclose(), and context manager lifecycles across sync and async public DaprWorkflowClients.

Issue reference

Please reference the issue this PR will close: Closes #1246

Checklist

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WORKFLOW SDK FEATURE REQUEST] Retry WaitForInstanceCompletion/Start on a server-sent CANCELLED

2 participants